package com.my.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.*;
import com.my.util.FileUpload;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;


/**
 * <p>
 * 妈妈护理记录 前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-08-24
 */
@Controller
@RequestMapping("/motherNursing")
public class MotherNursingController {
    Logger logger=Logger.getLogger(WorkguidaceController.class);

    @Autowired
    MotherNursingService motherNursingService;
    @Autowired
    FileService fileService;
    @Autowired
    BabyNursingService babyNursingService;
    @Autowired
    RoomService roomService;
    @Autowired
    UmbilicalService umbilicalService;
    @Autowired
    FeedService feedService;
    @Autowired
    BottleService bottleService;
    @Autowired
    ShitService shitService;
    @Autowired
    UrineService urineService;
    @Autowired
    MilkService milkService;
    @Autowired
    FrequencyService frequencyService;

   /* @RequestMapping("selectAll")
    public String selectAll(Long roomId,Long id){
        //根据房间号 获取 房间id
        Map<String,Object> map1 = new HashMap<>();
        map1.put("room_name",roomId);
        List<Room> rooms = roomService.selectByMap(map1);
        String newRoomId = String.valueOf(rooms.get(0).getId());
        //2根据房间id 获取妈妈id
       Map<String ,Object> map2 = new HashMap<>();
       map2.put("roomId",id);
       List<MotherNursing> list1 = motherNursingService.selectByMap(map2);



       int mid = 0;
        //3 根据妈妈id 获取所有消毒表
        Map<String,Object> map = new HashMap();
        map.put("mid", mid);
        List<Umbilical> umbilicals = umbilicalService.selectByMap(map);
        //4 根据妈妈id 获取所有喂养表
        List<Feed> feeds = feedService.selectByMap(map);
        String data = null;
        return  data;
    }*/


    /**
     * 添加
     * @param param
     * @return
     */
    @RequestMapping("addmother")
    @ResponseBody
    public String addmother(String param,HttpSession session) {
        MotherNursing motherNursing= JSON.parseObject(param,MotherNursing.class);
        motherNursing.setIsDelete("2");
        motherNursing.setDelete("1");
        motherNursing.setCreateTime(new Date().getTime());
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        motherNursing.setAreaid(areaid);
        System.out.println(motherNursing);
        if (motherNursingService.insert(motherNursing)) {
            long id = motherNursing.getId();

            logger.info("{addmother|保存成功}");
            return "保存成功";
        } else {
            logger.info("{addmother|保存失败}");
            return "保存失败";
        }
    }

    /**
     * 查询所有数据
     * @param voPage
     * @return
     */
    @RequestMapping("/selectMoterNursing")
    @ResponseBody
    public ResultPage<MotherNursing> selectMoterNursing(String lin,String data,VoPage voPage,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Map map=new HashMap();
           map.put("lin",lin);
           map.put("data",data);
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        ResultPage<MotherNursing> resultPage = motherNursingService.selectMyPage(map,voPage,areaid,admin);
        return  resultPage;

   }

    /**
     * 删除妈妈护理记录
     * @param id
     * @return
     */
    @RequestMapping("/deleteMotherNursing")
    @ResponseBody

    public boolean deleteMotherNursing(Long id){
        MotherNursing motherNursing= new MotherNursing();
        motherNursing.setDelete("2");
        motherNursing.setId(id);

        return motherNursingService.deleteById(motherNursing    );
}

    /**
     * 修改妈妈护理记录
     * @param
     * @return
     */
    @RequestMapping("/updateMotherNursing")
    @ResponseBody
    public String updateMotherNursing(String param ){
        MotherNursing motherNursing = JSONObject.parseObject(param,MotherNursing.class);
        if(motherNursingService.updateById(motherNursing)){
            return "修改成功";
        }else{
            return "修改失败";
        }
}

    @RequestMapping("/mama")
    public  String  mama(){
        return "Cover_management";
    }

    /**
     * 添加页面
     * @return
     */
    @RequestMapping("/mother_add")
    public String mother(){
        return  "/Alert/mother_add";
    }

    /**
     * 修改页面
     * @return
     */
    @RequestMapping("/mother_edit")
    public String mother_edit(){
        return "/Alert/mother_edit";
    }

    /**
     * 跳转关联文件页面
     * @return
     */
    @RequestMapping("/RelactionFile.html")
    public  String  RelactionFile(Long RelactionId,Model model){
        model.addAttribute("RelactionId",RelactionId);
        return "/Alert/RelactionFile";
    }
   /* @RequestMapping("/RelactionFile.html")
    public  String  RelactionFile(@RequestParam("homeId") Long homeId ,Model model){
        model.addAttribute("homeId",homeId);
        return "/Alert/RelactionFile";
    }*/



    /**
     * 查询该记录的所有文件
     * @return
     */
    @RequestMapping("/findFile")
    @ResponseBody
    public  List<com.my.bean.File>  findFile(Long RelactionId,HttpSession session ){
        List<com.my.bean.File> files = new ArrayList<>();


        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        if(admin){
            Map map=new HashMap<>();
            map.put("relationId",RelactionId);
            files= fileService.selectByMap(map);
        }else {
            Long areaid=((User)session.getAttribute("user")).getAreaId();
            Map map=new HashMap<>();
            map.put("relationId",RelactionId);
            map.put("areaid",areaid);
             files= fileService.selectByMap(map);
        }



        return files;
    }

    /**
     * 上传文件
     * @return
     */
    @RequestMapping("/uploadFile")
    @ResponseBody
    public  String  uploadFile(@RequestParam("file") MultipartFile multipartFile,Long RelactionId,HttpSession session){
       if (fileService.uploadFile(multipartFile,RelactionId,session)){
           return "上传成功";
       }else{
           return  "失败";
       }
    }


    /**
     * 下载文件
     * @return
     */
    @RequestMapping("/dowLoad")
    @ResponseBody
    public  String  dowLoad(HttpServletResponse response,Long fileId){
        Map map=new HashMap<>();
        map.put("id",fileId);
       List<com.my.bean.File> files= fileService.selectByMap(map);
        try {
            FileUpload.downLoad(response,files.get(0));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "该文件已损坏....无法下载";
        }
        return null;
    }
    /**
     * 删除文件
     * @return
     */
    @RequestMapping("/deleteFile")
    @ResponseBody
    public  boolean  deleteFile( Long fileId){
       return  fileService.deleteFile(fileId);
    }







    /**
     * 返回编辑页面
     * @return
     */
    @RequestMapping("/editWord1")
    public String edit(@RequestParam("fileName") String fileName,
                       @RequestParam("url") String url,
                       HttpSession session
    ){
        session.setAttribute("fileName",fileName);
        session.setAttribute("lujing",url);
        System.out.println(session.getAttribute("lujing"));
        return "editWord";
    }

    @RequestMapping("/editWord")
    public String edit(){
        return "editWord";
    }





    /**
     * 点击放大镜跳转页面
     * @return
     */
    @RequestMapping("/word")
    public String word(@RequestParam("id") long id,HttpServletRequest request){
        request.setAttribute("id",id);
        return  "/Alert/word";
    }

    /**
     * 查询该记录有多少文件
     * @param idd
     * @return
     */
    @RequestMapping("/selectWord")
    @ResponseBody
    public List<MotherNursing> selectWord(@RequestParam("idd")Long idd){
        return motherNursingService.selectWord(idd);
    }


    /**
     * 返回表格
     * @return
     */
    @RequestMapping("/untitled")
    public String homeId(){
        return  "untitled";
    }



    //查询护理记录
    @RequestMapping("/selectByHomeId")
    @ResponseBody
    public List<MotherNursing> selectByHomeId(Long homeId){
        return motherNursingService.selectByHomeId(homeId);
    }


//查询宝宝
    @RequestMapping("/selectBabyNursing")
    @ResponseBody
    public List<BabyNursing> selectBabyNursing(@RequestParam("homeId")Long homeId){
        return motherNursingService.selectBabyNursing(homeId);
    }


    /**
     * 页面添加
     */
    @RequestMapping("/insertInput")
    @ResponseBody
    public String  insertInput(String param,Long id){
        //判断是否插入成功 如果b为true 就成功
        boolean b = false;
        //System.out.println(param);
        Map<String,Object> map = JSON.parseObject(param,Map.class);
        //1 获得房间号
        Object roomId = map.get("roomId");
        //2  根据房间号查出 房间id
        Map<String,Object> map1 = new HashMap<>();
        map1.put("room_name",roomId);
        List<Room> rooms = roomService.selectByMap(map1);
        String newRoomId = String.valueOf(rooms.get(0).getId());
        //3 重新赋值
        map.put("roomId", newRoomId);
        System.out.println("rooms:"+rooms);
        Object um1 = map.get("um1");
        Object um2 = map.get("um2");
        Object um3 = map.get("um3");
        //喂养时间
        Object feed1 = map.get("feed1");
        Object feed2 = map.get("feed2");
        Object feed3 = map.get("feed3");
        Object feed4 = map.get("feed4");
        Object feed5 = map.get("feed5");
        Object feed6 = map.get("feed6");
        Object feed7 = map.get("feed7");
        Object feed8 = map.get("feed8");
        Object feed9 = map.get("feed9");
        Object feed10 = map.get("feed10");
        Object feed11 = map.get("feed11");
        Object feed12 = map.get("feed12");
        Object feed13 = map.get("feed13");
        //奶瓶消毒
        Object bottle1 = map.get("bottle1");
        Object bottle2 = map.get("bottle2");
        Object bottle3 = map.get("bottle3");
        Object bottle4 = map.get("bottle4");
        Object bottle5 = map.get("bottle5");
        Object bottle6 = map.get("bottle6");
        Object bottle7 = map.get("bottle7");
        Object bottle8 = map.get("bottle8");
        Object bottle9 = map.get("bottle9");
        Object bottle10 = map.get("bottle10");
        Object bottle11 = map.get("bottle11");
        Object bottle12 = map.get("bottle12");
        Object bottle13 = map.get("bottle13");
        //大便观察
        Object shitTime1 = map.get("shitTime1");
        Object shitTime2 = map.get("shitTime2");
        Object shitTime3 = map.get("shitTime3");
        Object shitTime4 = map.get("shitTime4");
        Object shitTime5 = map.get("shitTime5");
        Object shitTime6 = map.get("shitTime6");
        Object shitTime7 = map.get("shitTime7");
        Object shitTime8 = map.get("shitTime8");
        Object shitTime9 = map.get("shitTime9");
        Object shitTime10 = map.get("shitTime10");
        Object shitTime11 = map.get("shitTime11");
        Object shitTime12 = map.get("shitTime12");
        Object shitTime13 = map.get("shitTime13");
        //小便观察
        Object urineTime1 = map.get("urineTime1");
        Object urineTime2 = map.get("urineTime2");
        Object urineTime3 = map.get("urineTime3");
        Object urineTime4 = map.get("urineTime4");
        Object urineTime5 = map.get("urineTime5");
        Object urineTime6 = map.get("urineTime6");
        Object urineTime7 = map.get("urineTime7");
        Object urineTime8 = map.get("urineTime8");
        Object urineTime9 = map.get("urineTime9");
        Object urineTime10 = map.get("urineTime10");
        Object urineTime11 = map.get("urineTime11");
        Object urineTime12 = map.get("urineTime12");
        Object urineTime13 = map.get("urineTime13");
        //挤奶时间
        Object milkTime1 = map.get("milkTime1");
        Object milkTime2 = map.get("milkTime2");
        Object milkTime3 = map.get("milkTime3");
        Object milkTime4 = map.get("milkTime4");
        //多少次
        Object frequency1 = map.get("frequency1");
        Object frequency2 = map.get("frequency2");
        Object frequency3 = map.get("frequency3");
        Object frequency4 = map.get("frequency4");
        Object frequency5 = map.get("frequency5");
        Object frequency6 = map.get("frequency6");
        Object frequency7 = map.get("frequency7");
        Object remarks001 = map.get("remarks001");


        /*Object feed1 = map.get("feed1");*/
        //System.out.println("value:"+um1);
        //map.put("umbilicalTime",um1.toString().replace("-",""));
        //System.out.println("value:"+um2);
       // map.put("umbilicalTime",um2.toString().replace("-",""));
        //System.out.println("value:"+um3);
        //map.put("umbilicalTime",um3.toString().replace("-",""));
        param = JSON.toJSONString(map);
        //System.out.println(param);
        //把妈妈的id给传到消毒时间表中的mid中
        Umbilical umbilical1= JSON.parseObject(um1.toString(),Umbilical.class);
        System.out.println(umbilical1);
        Umbilical umbilical2= JSON.parseObject(um2.toString(),Umbilical.class);
        System.out.println(umbilical2);
        Umbilical umbilical3= JSON.parseObject(um3.toString(),Umbilical.class);
        System.out.println(umbilical3);
        //喂养时间
        Feed feed= JSON.parseObject(feed1.toString(),Feed.class);
        //System.out.println("长度:"+feed.getFeedVolume().length());
        System.out.println("feed:"+feed);
        Feed f1= JSON.parseObject(feed2.toString(),Feed.class);
        System.out.println("feed:"+f1);
        Feed f2= JSON.parseObject(feed3.toString(),Feed.class);
        System.out.println("feed:"+f2);
        Feed f3= JSON.parseObject(feed4.toString(),Feed.class);
        System.out.println("feed:"+f3);
        Feed f4= JSON.parseObject(feed5.toString(),Feed.class);
        System.out.println("feed:"+f4);
        Feed f5= JSON.parseObject(feed6.toString(),Feed.class);
        System.out.println("feed:"+f5);
        Feed f6= JSON.parseObject(feed7.toString(),Feed.class);
        System.out.println("feed:"+f6);
        Feed f7= JSON.parseObject(feed8.toString(),Feed.class);
        System.out.println("feed:"+f7);
        Feed f8= JSON.parseObject(feed9.toString(),Feed.class);
        System.out.println("feed:"+f8);
        Feed f9= JSON.parseObject(feed10.toString(),Feed.class);
        System.out.println("feed:"+f9);
        Feed f10= JSON.parseObject(feed11.toString(),Feed.class);
        System.out.println("feed:"+f10);
        Feed f11= JSON.parseObject(feed12.toString(),Feed.class);
        System.out.println("feed:"+f11);
        Feed f12= JSON.parseObject(feed13.toString(),Feed.class);
        System.out.println("feed:"+f12);
        //奶瓶消毒
        Bottle b1= JSON.parseObject(bottle1.toString(),Bottle.class);
        System.out.println("bottle:"+b1);
        Bottle b2= JSON.parseObject(bottle2.toString(),Bottle.class);
        System.out.println("bottle:"+b2);
        Bottle b3= JSON.parseObject(bottle3.toString(),Bottle.class);
        System.out.println("bottle:"+b3);
        Bottle b4= JSON.parseObject(bottle4.toString(),Bottle.class);
        System.out.println("bottle:"+b4);
        Bottle b5= JSON.parseObject(bottle5.toString(),Bottle.class);
        System.out.println("bottle:"+b5);
        Bottle b6= JSON.parseObject(bottle6.toString(),Bottle.class);
        System.out.println("bottle:"+b6);
        Bottle b7= JSON.parseObject(bottle7.toString(),Bottle.class);
        System.out.println("bottle:"+b7);
        Bottle b8= JSON.parseObject(bottle8.toString(),Bottle.class);
        System.out.println("bottle:"+b8);
        Bottle b9= JSON.parseObject(bottle9.toString(),Bottle.class);
        System.out.println("bottle:"+b9);
        Bottle b10= JSON.parseObject(bottle10.toString(),Bottle.class);
        System.out.println("bottle:"+b10);
        Bottle b11= JSON.parseObject(bottle11.toString(),Bottle.class);
        System.out.println("bottle:"+b11);
        Bottle b12= JSON.parseObject(bottle12.toString(),Bottle.class);
        System.out.println("bottle:"+b12);
        Bottle b13= JSON.parseObject(bottle13.toString(),Bottle.class);
        System.out.println("bottle:"+b13);
        //大便观察
        Shit shit1= JSON.parseObject(shitTime1.toString(),Shit.class);
        System.out.println(shit1);
        Shit shit2= JSON.parseObject(shitTime2.toString(),Shit.class);
        System.out.println(shit2);
        Shit shit3= JSON.parseObject(shitTime3.toString(),Shit.class);
        System.out.println(shit3);
        Shit shit4= JSON.parseObject(shitTime4.toString(),Shit.class);
        System.out.println(shit4);
        Shit shit5= JSON.parseObject(shitTime5.toString(),Shit.class);
        System.out.println(shit5);
        Shit shit6= JSON.parseObject(shitTime6.toString(),Shit.class);
        System.out.println(shit6);
        Shit shit7= JSON.parseObject(shitTime7.toString(),Shit.class);
        System.out.println(shit7);
        Shit shit8= JSON.parseObject(shitTime8.toString(),Shit.class);
        System.out.println(shit8);
        Shit shit9= JSON.parseObject(shitTime9.toString(),Shit.class);
        System.out.println(shit9);
        Shit shit10= JSON.parseObject(shitTime10.toString(),Shit.class);
        System.out.println(shit10);
        Shit shit11= JSON.parseObject(shitTime11.toString(),Shit.class);
        System.out.println(shit11);
        Shit shit12= JSON.parseObject(shitTime12.toString(),Shit.class);
        System.out.println(shit12);
        Shit shit13= JSON.parseObject(shitTime13.toString(),Shit.class);
        System.out.println(shit13);
        //小便观察 urineTime1
        Urine urine1= JSON.parseObject(urineTime1.toString(),Urine.class);
        System.out.println(urine1);
        Urine urine2= JSON.parseObject(urineTime2.toString(),Urine.class);
        System.out.println(urine2);
        Urine urine3= JSON.parseObject(urineTime3.toString(),Urine.class);
        System.out.println(urine3);
        Urine urine4= JSON.parseObject(urineTime4.toString(),Urine.class);
        System.out.println(urine4);
        Urine urine5= JSON.parseObject(urineTime5.toString(),Urine.class);
        System.out.println(urine5);
        Urine urine6= JSON.parseObject(urineTime6.toString(),Urine.class);
        System.out.println(urine6);
        Urine urine7= JSON.parseObject(urineTime7.toString(),Urine.class);
        System.out.println(urine7);
        Urine urine8= JSON.parseObject(urineTime8.toString(),Urine.class);
        System.out.println(urine8);
        Urine urine9= JSON.parseObject(urineTime9.toString(),Urine.class);
        System.out.println(urine9);
        Urine urine10= JSON.parseObject(urineTime10.toString(),Urine.class);
        System.out.println(urine10);
        Urine urine11= JSON.parseObject(urineTime11.toString(),Urine.class);
        System.out.println(urine11);
        Urine urine12= JSON.parseObject(urineTime12.toString(),Urine.class);
        System.out.println(urine12);
        Urine urine13= JSON.parseObject(urineTime13.toString(),Urine.class);
        System.out.println(urine13);
        //挤奶时间
        Milk milk1 = JSON.parseObject(milkTime1.toString(),Milk.class);
        System.out.println(milkTime1);
        Milk milk2 = JSON.parseObject(milkTime2.toString(),Milk.class);
        System.out.println(milkTime2);
        Milk milk3 = JSON.parseObject(milkTime3.toString(),Milk.class);
        System.out.println(milkTime3);
        Milk milk4 = JSON.parseObject(milkTime4.toString(),Milk.class);
        System.out.println(milkTime4);
        //多少词
        Frequency fr1 = JSON.parseObject(frequency1.toString(),Frequency.class);
        System.out.println(fr1);
        Frequency fr2 = JSON.parseObject(frequency2.toString(),Frequency.class);
        System.out.println(fr2);
        Frequency fr3 = JSON.parseObject(frequency3.toString(),Frequency.class);
        System.out.println(fr3);
        Frequency fr4 = JSON.parseObject(frequency4.toString(),Frequency.class);
        System.out.println(fr4);
        Frequency fr5 = JSON.parseObject(frequency5.toString(),Frequency.class);
        System.out.println(fr5);
        Frequency fr6 = JSON.parseObject(frequency6.toString(),Frequency.class);
        System.out.println(fr6);
        Frequency fr7 = JSON.parseObject(frequency7.toString(),Frequency.class);
        System.out.println(fr7);
        Frequency fr8 = JSON.parseObject(remarks001.toString(),Frequency.class);
        System.out.println(fr8);








        //创建一个List集合,把数据给设置到List集合中
        List<Umbilical> list = new ArrayList<>();
        if(umbilical1.getUmbilicalTime()!=null && !umbilical1.getUmbilicalCord().equals("") ){
            umbilical1.setMid(Long.valueOf(newRoomId));
            list.add(umbilical1);
        }
        if(umbilical2.getUmbilicalTime()!=null && !umbilical2.getUmbilicalCord().equals("") ){
            umbilical2.setMid(Long.valueOf(newRoomId));
            list.add(umbilical2);
        }
        if(umbilical3.getUmbilicalTime()!=null && !umbilical3.getUmbilicalCord().equals("") ){
            umbilical3.setMid(Long.valueOf(newRoomId));
            list.add(umbilical3);
        }
        //喂养时间
        List<Feed> list1 = new ArrayList<>();
        if(feed.getFeedTime()!=null && feed.getFeedVolume().length()!=0 ){
            feed.setMid(Long.valueOf(newRoomId));
            list1.add(feed);
        }
        if(f1.getFeedTime()!=null && f1.getFeedVolume().length()!=0 ){
            f1.setMid(Long.valueOf(newRoomId));
            list1.add(f1);
        }
        if(f2.getFeedTime()!=null && f2.getFeedVolume().length()!=0 ){
            f2.setMid(Long.valueOf(newRoomId));
            list1.add(f2);
        }
        if(f3.getFeedTime()!=null && f3.getFeedVolume().length()!=0 ){
            f3.setMid(Long.valueOf(newRoomId));
            list1.add(f3);
        }
        if(f4.getFeedTime()!=null && f4.getFeedVolume().length()!=0 ){
            f4.setMid(Long.valueOf(newRoomId));
            list1.add(f4);
        }
        if(f5.getFeedTime()!=null && f5.getFeedVolume().length()!=0 ){
            f5.setMid(Long.valueOf(newRoomId));
            list1.add(f5);
        }
        if(f6.getFeedTime()!=null && f6.getFeedVolume().length()!=0 ){
            f6.setMid(Long.valueOf(newRoomId));
            list1.add(f6);
        }
        if(f7.getFeedTime()!=null && f7.getFeedVolume().length()!=0 ){
            f7.setMid(Long.valueOf(newRoomId));
            list1.add(f7);
        }
        if(f8.getFeedTime()!=null && f8.getFeedVolume().length()!=0 ){
            f8.setMid(Long.valueOf(newRoomId));
            list1.add(f8);
        }
        if(f9.getFeedTime()!=null && f9.getFeedVolume().length()!=0 ){
            f9.setMid(Long.valueOf(newRoomId));
            list1.add(f9);
        }
        if(f10.getFeedTime()!=null && f10.getFeedVolume().length()!=0 ){
            f10.setMid(Long.valueOf(newRoomId));
            list1.add(f10);
        }
        if(f11.getFeedTime()!=null && f11.getFeedVolume().length()!=0 ){
            f11.setMid(Long.valueOf(newRoomId));
            list1.add(f11);
        }
        if(f12.getFeedTime()!=null && f12.getFeedVolume().length()!=0 ){
            f12.setMid(Long.valueOf(newRoomId));
            list1.add(f12);
        }
        //奶瓶消毒
        List<Bottle> list2 = new ArrayList<>();
        if(b1.getBottle()!=null && b1.getBottle().length()!=0 ){
            b1.setMid(Long.valueOf(newRoomId));
            list2.add(b1);
        }
        if(b2.getBottle()!=null && b2.getBottle().length()!=0 ){
            b2.setMid(Long.valueOf(newRoomId));
            list2.add(b2);
        }
        if(b3.getBottle()!=null && b3.getBottle().length()!=0 ){
            b3.setMid(Long.valueOf(newRoomId));
            list2.add(b3);
        }
        if(b4.getBottle()!=null && b4.getBottle().length()!=0 ){
            b4.setMid(Long.valueOf(newRoomId));
            list2.add(b4);
        }
        if(b5.getBottle()!=null && b5.getBottle().length()!=0 ){
            b5.setMid(Long.valueOf(newRoomId));
            list2.add(b5);
        }
        if(b6.getBottle()!=null && b6.getBottle().length()!=0 ){
            b6.setMid(Long.valueOf(newRoomId));
            list2.add(b6);
        }
        if(b7.getBottle()!=null && b7.getBottle().length()!=0 ){
            b7.setMid(Long.valueOf(newRoomId));
            list2.add(b7);
        }
        if(b8.getBottle()!=null && b8.getBottle().length()!=0 ){
            b8.setMid(Long.valueOf(newRoomId));
            list2.add(b8);
        }
        if(b9.getBottle()!=null && b9.getBottle().length()!=0 ){
            b9.setMid(Long.valueOf(newRoomId));
            list2.add(b9);
        }
        if(b10.getBottle()!=null && b10.getBottle().length()!=0 ){
            b10.setMid(Long.valueOf(newRoomId));
            list2.add(b10);
        }
        if(b11.getBottle()!=null && b11.getBottle().length()!=0 ){
            b11.setMid(Long.valueOf(newRoomId));
            list2.add(b11);
        }
        if(b12.getBottle()!=null && b12.getBottle().length()!=0 ){
            b12.setMid(Long.valueOf(newRoomId));
            list2.add(b12);
        }
        if(b13.getBottle()!=null && b13.getBottle().length()!=0 ){
            b13.setMid(Long.valueOf(newRoomId));
            list2.add(b13);
        }
        //大便观察
        List<Shit> list3 = new ArrayList<>();
        if(shit1.getShitTime()!=null && shit1.getShitChromatic().length()!=0 ){
            shit1.setMid(Long.valueOf(newRoomId));
            list3.add(shit1);
        }
        if(shit2.getShitTime()!=null && shit2.getShitChromatic().length()!=0 ){
            shit2.setMid(Long.valueOf(newRoomId));
            list3.add(shit2);
        }
        if(shit3.getShitTime()!=null && shit3.getShitChromatic().length()!=0 ){
            shit3.setMid(Long.valueOf(newRoomId));
            list3.add(shit3);
        }
        if(shit4.getShitTime()!=null && shit4.getShitChromatic().length()!=0 ){
            shit4.setMid(Long.valueOf(newRoomId));
            list3.add(shit4);
        }
        if(shit5.getShitTime()!=null && shit5.getShitChromatic().length()!=0 ){
            shit5.setMid(Long.valueOf(newRoomId));
            list3.add(shit5);
        }
        if(shit6.getShitTime()!=null && shit6.getShitChromatic().length()!=0 ){
            shit6.setMid(Long.valueOf(newRoomId));
            list3.add(shit6);
        }
        if(shit7.getShitTime()!=null && shit7.getShitChromatic().length()!=0 ){
            shit7.setMid(Long.valueOf(newRoomId));
            list3.add(shit7);
        }
        if(shit8.getShitTime()!=null && shit8.getShitChromatic().length()!=0 ){
            shit8.setMid(Long.valueOf(newRoomId));
            list3.add(shit8);
        }
        if(shit9.getShitTime()!=null && shit9.getShitChromatic().length()!=0 ){
            shit9.setMid(Long.valueOf(newRoomId));
            list3.add(shit9);
        }
        if(shit10.getShitTime()!=null && shit10.getShitChromatic().length()!=0 ){
            shit10.setMid(Long.valueOf(newRoomId));
            list3.add(shit10);
        }
        if(shit11.getShitTime()!=null && shit11.getShitChromatic().length()!=0 ){
            shit11.setMid(Long.valueOf(newRoomId));
            list3.add(shit11);
        }
        if(shit12.getShitTime()!=null && shit12.getShitChromatic().length()!=0 ){
            shit12.setMid(Long.valueOf(newRoomId));
            list3.add(shit12);
        }
        if(shit13.getShitTime()!=null && shit13.getShitChromatic().length()!=0 ){
            shit13.setMid(Long.valueOf(newRoomId));
            list3.add(shit13);
        }
        //小便观察
        List<Urine> list4 = new ArrayList<>();
        if(urine1.getUrineTime()!=null && urine1.getUrineChromatic().length()!=0 ){
            urine1.setMid(Long.valueOf(newRoomId));
            list4.add(urine1);
        }
        if(urine2.getUrineTime()!=null && urine2.getUrineChromatic().length()!=0 ){
            urine2.setMid(Long.valueOf(newRoomId));
            list4.add(urine2);
        }
        if(urine3.getUrineTime()!=null && urine3.getUrineChromatic().length()!=0 ){
            urine3.setMid(Long.valueOf(newRoomId));
            list4.add(urine3);
        }
        if(urine4.getUrineTime()!=null && urine4.getUrineChromatic().length()!=0 ){
            urine4.setMid(Long.valueOf(newRoomId));
            list4.add(urine4);
        }
        if(urine5.getUrineTime()!=null && urine5.getUrineChromatic().length()!=0 ){
            urine5.setMid(Long.valueOf(newRoomId));
            list4.add(urine5);
        }
        if(urine6.getUrineTime()!=null && urine6.getUrineChromatic().length()!=0 ){
            urine6.setMid(Long.valueOf(newRoomId));
            list4.add(urine6);
        }
        if(urine7.getUrineTime()!=null && urine7.getUrineChromatic().length()!=0 ){
            urine7.setMid(Long.valueOf(newRoomId));
            list4.add(urine7);
        }
        if(urine8.getUrineTime()!=null && urine8.getUrineChromatic().length()!=0 ){
            urine8.setMid(Long.valueOf(newRoomId));
            list4.add(urine8);
        }
        if(urine9.getUrineTime()!=null && urine9.getUrineChromatic().length()!=0 ){
            urine9.setMid(Long.valueOf(newRoomId));
            list4.add(urine9);
        }
        if(urine10.getUrineTime()!=null && urine10.getUrineChromatic().length()!=0 ){
            urine10.setMid(Long.valueOf(newRoomId));
            list4.add(urine10);
        }
        if(urine11.getUrineTime()!=null && urine11.getUrineChromatic().length()!=0 ){
            urine11.setMid(Long.valueOf(newRoomId));
            list4.add(urine11);
        }
        if(urine12.getUrineTime()!=null && urine12.getUrineChromatic().length()!=0 ){
            urine12.setMid(Long.valueOf(newRoomId));
            list4.add(urine12);
        }
        if(urine13.getUrineTime()!=null && urine13.getUrineChromatic().length()!=0 ){
            urine13.setMid(Long.valueOf(newRoomId));
            list4.add(urine13);
        }
        //挤奶时间
        List<Milk> list5 = new ArrayList<>();
        if(milk1.getMilkTime()!=null && milk1.getMilkVolume().length()!=0 ){
            milk1.setMid(Long.valueOf(newRoomId));
            list5.add(milk1);
        }
        if(milk2.getMilkTime()!=null && milk2.getMilkVolume().length()!=0 ){
            milk2.setMid(Long.valueOf(newRoomId));
            list5.add(milk2);
        }
        if(milk3.getMilkTime()!=null && milk3.getMilkVolume().length()!=0 ){
            milk3.setMid(Long.valueOf(newRoomId));
            list5.add(milk3);
        }
        if(milk4.getMilkTime()!=null && milk4.getMilkVolume().length()!=0 ){
            milk4.setMid(Long.valueOf(newRoomId));
            list5.add(milk4);
        }
        //多少次
        List<Frequency> list6 = new ArrayList<>();
        if(fr1.getFrequency1()!=null && fr1.getFrequency1().length()!=0 ){
            fr1.setMid(Long.valueOf(newRoomId));
            list6.add(fr1);
        }
        if(fr2.getFrequency2()!=null && fr2.getFrequency2().length()!=0 ){
            fr2.setMid(Long.valueOf(newRoomId));
            list6.add(fr2);
        }
        if(fr3.getFrequency3()!=null && fr3.getFrequency3().length()!=0 ){
            fr3.setMid(Long.valueOf(newRoomId));
            list6.add(fr3);
        }
        if(fr4.getFrequency4()!=null && fr4.getFrequency4().length()!=0 ){
            fr4.setMid(Long.valueOf(newRoomId));
            list6.add(fr4);
        }
        if(fr5.getFrequency5()!=null && fr5.getFrequency5().length()!=0 ){
            fr5.setMid(Long.valueOf(newRoomId));
            list6.add(fr5);
        }
        if(fr6.getFrequency6()!=null && fr6.getFrequency6().length()!=0 ){
            fr6.setMid(Long.valueOf(newRoomId));
            list6.add(fr6);
        }
        if(fr7.getFrequency7()!=null && fr7.getFrequency7().length()!=0 ){
            fr7.setMid(Long.valueOf(newRoomId));
            list6.add(fr7);
        }
        if(fr8.getRemarks001()!=null && fr8.getRemarks001().length()!=0 ){
            fr8.setMid(Long.valueOf(newRoomId));
            list6.add(fr8);
        }





        //System.out.println("111111"+umbilical1);
        //在执行多条数据插入
        //System.out.println(list.size());
        if(list.size()!=0 && list!=null){
           b =  umbilicalService.insertBatch(list);
        }
        //喂养
        if(list1.size()!=0 && list1!=null){
            b = feedService.insertBatch(list1);
        }
        //奶瓶消毒时间
        if(list2.size()!=0 && list2!=null){
            b = bottleService.insertBatch(list2);
        }
        //大便观察
        if(list3.size()!=0 && list3!=null){
            b = shitService.insertBatch(list3);
        }
        //小便
        if(list4.size()!=0 && list4!=null){
            b = urineService.insertBatch(list4);
        }
        //挤奶时间
        if(list5.size()!=0 && list5!=null){
            b = milkService.insertBatch(list5);
        }
        //多少次
        if(list6.size()!=0 && list6!=null){
            b = frequencyService.insertBatch(list6);
        }



        if(b){
            return "保存成功";
        }
        logger.info("{addmother|保存失败}");
        return "保存失败";
    }


    /**
     * 返回写日报的页面
     */
    @RequestMapping("/motherDay")
    public String motherDay(){
        return "motherDay";
    }


    /**
     * 返回写月报的
     */
    @RequestMapping("/motherMonth")
    public String  motherMonth(){
        return "motherMonthlyReport";
    }




}
